Compilers are programs that translate a source program written in a source language into a target program written in a target language. For example, a compiler may translate a program written in a high level language (such as C++) into compiled code that can be understood by a processor. During compiling a source program into a target program, certain optimizations can be made which can significantly improve running time and/or space requirements of the target program.
One technique of optimizing target code includes register promotion. With this technique, sections of code are identified in which it is safe to move values of data objects from memory to registers. These sections of code are then re-written in order to recall those values from the registers instead of from memory. Register promotion is regarded as a form of code optimization because instructions generated to access data objects in registers are more efficient than the same instructions accessing the data objects from memory.
Certain programming languages require exceptions to be accurately reported. This means that all effects of statements executed and expressions evaluated before the point at which an exception occurred should appear to have taken place.
One programming language requiring precise exception reporting is Java (™). Java (™) which was developed by Sun Microsystems, Inc. of Palo Alto, Calif. has become very popular. One advantage of Java (™) is that it is a compact platform-neutral-object-oriented programming language that, when compiled, represents instructions as platform-independent byte codes. These byte codes can be translated using a compiler such as the Just-In-Time (™) (JIT) compiler, that converts the Java (™) byte codes into instructions within the native instruction set of a particular hardware platform.
Code optimization using register promotion, as discussed above can result in an imprecise exception. Because of the requirement of the precise exception reporting, during compilation of Java(™) code, the JIT compiler must ensure that any optimization transformation does not violate the precise exception reporting semantic.
One way of satisfying the precise exception reporting semantic is to analyze sections of the code in which it is desired to perform register promotion in order to determine whether a possibility of violating the semantic exists. If it exists then the register promotion transformation is not performed. This is a very conservative approach which leaves the original code in unoptimized form.